package com.module.framework.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.module.framework.constants.SystemConstants;
import com.module.framework.domain.Book;
import com.module.framework.domain.Category;
import com.module.framework.domain.Public;
import com.module.framework.dto.BookListDTO;
import com.module.framework.dto.PbulicDTO;
import com.module.framework.mapper.PublicMapper;
import com.module.framework.service.PublicService;
import com.module.framework.utils.BeanCopyUtils;
import com.module.framework.vo.PageVO;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

@Service
public class PublicServiceImpl extends ServiceImpl<PublicMapper, Public> implements PublicService {

    @Resource
    private PublicMapper publicMapper;

    @Override
    public PageVO publicList(PbulicDTO publicDTO) {
        Integer pageNum = publicDTO.getPageNum();
        LambdaQueryWrapper<Public> queryWrapper = new LambdaQueryWrapper<>();
        if (Objects.nonNull(publicDTO.getCreateTime())) {
            queryWrapper.ge(Objects.nonNull(publicDTO.getCreateTime().get(0)), Public::getCreateTime, publicDTO.getCreateTime().get(0));
            queryWrapper.le(Objects.nonNull(publicDTO.getCreateTime().get(1)), Public::getCreateTime, publicDTO.getCreateTime().get(1));
        }
        Page<Public> page = new Page<>(pageNum, publicDTO.getPageSize());
        IPage<Public> pageResult = publicMapper.selectPage(page, queryWrapper);
        PageVO pageVO = new PageVO(pageResult.getRecords(), (int) pageResult.getTotal());

        return pageVO;
    }

    @Override
    public List<Public> getList() {
        List<Public> list = publicMapper.selectList(null);
        return list;
    }
}
